package com.mysite.seckill.commons.exception;

public enum BusinessError {

    COMMON_ERROR(1, "服务器内部错误"),

    SECKILL_ACTIVITY_NOT_EXISTED_ERROR(1001, "秒杀活动不存在"),
    SECKILL_NUMBER_BEYOND_LIMIT_ERROR(1002, "秒杀商品的数量超过指定额度"),
    SECKILL_OUT_OF_STOCK_ERROR(1003, "秒杀商品的库存不足"),
    SECKILL_USER_ALREADY_INVOLVED_ERROR(1004, "用户已经参与过了秒杀"),
    SECKILL_ACTIVITY_NOT_RUNNING_ERROR(1005, "秒杀活动尚未开始"),

    USER_USERNAME_OR_PASSWORD_ERROR(2001, "用户名或密码错误"),
    USER_SESSION_TIMEOUT_ERROR(2002, "用户信息已失效"),
    ;

    private Integer errorCode;
    private String errorMessage;

    private BusinessError(Integer errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public static BusinessError getError(int errorCode) {
        for (BusinessError error : BusinessError.values()) {
            if (errorCode == error.getErrorCode()) {
                return error;
            }
        }
        return null;
    }
}
